//
//  DKHomeAuthLoanHeadView.m
//  DanKU
//
//  Created by 吴斌 on 2023/11/9.
//

#import "DKHomeAuthLoanHeadView.h"
@interface DKHomeAuthLoanHeadView()
@property (nonatomic, strong)UILabel * dk_HomeAuthLoanValueLab;
@end
@implementation DKHomeAuthLoanHeadView
-(instancetype)init{
    if(self == [super init]){
        self.backgroundColor = UIColor.clearColor;
        [self dk_addSubView];
    }
    return self;
}
- (void)dk_addSubView{
    UILabel *dk_HomeAuthLoanHeadLab = [[UILabel alloc] init];
    dk_HomeAuthLoanHeadLab.textColor = DK_Hex(@"#333333");
    dk_HomeAuthLoanHeadLab.font = DK_FONT_Medium(15);
    dk_HomeAuthLoanHeadLab.text = @"My loans list";
    [self addSubview:dk_HomeAuthLoanHeadLab];
    [dk_HomeAuthLoanHeadLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(16)));
        make.top.equalTo(@(DK_IsWidthScale(7)));
        make.height.equalTo(@(DK_IsWidthScale(21)));
    }];
    
    self.dk_HomeAuthLoanValueLab = [[UILabel alloc] init];
    self.dk_HomeAuthLoanValueLab.textColor = DK_Hex(@"#333333");
    self.dk_HomeAuthLoanValueLab.font = DK_FONT_Regular(20);
    self.dk_HomeAuthLoanValueLab.text = @"₹0";
    [self addSubview:self.dk_HomeAuthLoanValueLab];
    [self.dk_HomeAuthLoanValueLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@(-DK_IsWidthScale(36)));
        make.top.equalTo(@(DK_IsWidthScale(0)));
        make.height.equalTo(@(DK_IsWidthScale(28)));
    }];
    UIImageView* dk_HomeAuthLoanValueImageView = [[UIImageView alloc] init];
    dk_HomeAuthLoanValueImageView.userInteractionEnabled = YES;
    dk_HomeAuthLoanValueImageView.image = DK_GetImage(@"dk_HomeAuthorizeLimitBack");
    [self addSubview:dk_HomeAuthLoanValueImageView];
    [dk_HomeAuthLoanValueImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@(-DK_IsWidthScale(14)));
        make.centerY.equalTo(self.dk_HomeAuthLoanValueLab);
        make.width.equalTo(@(DK_IsWidthScale(10)));
        make.height.equalTo(@(DK_IsWidthScale(10)));
    }];
    UIButton * dk_HomeAuthLoanBtn = [[UIButton alloc] init];
    [dk_HomeAuthLoanBtn addTarget:self action:@selector(jumpOrder) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:dk_HomeAuthLoanBtn];
    [dk_HomeAuthLoanBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.dk_HomeAuthLoanValueLab);
        make.right.equalTo(dk_HomeAuthLoanValueImageView);
        make.top.equalTo(self.dk_HomeAuthLoanValueLab);
        make.bottom.equalTo(self.dk_HomeAuthLoanValueLab);
    }];
    
    UIView *dk_authHomeLoanAlertBgView = [[UIView alloc] init];
    dk_authHomeLoanAlertBgView.backgroundColor = DK_HexA(@"#FF0000", 0.05);
    dk_authHomeLoanAlertBgView.layer.cornerRadius = DK_IsWidthScale(10);
    dk_authHomeLoanAlertBgView.clipsToBounds = YES;
    [self addSubview:dk_authHomeLoanAlertBgView];
    [dk_authHomeLoanAlertBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(15)));
        make.right.equalTo(@(-DK_IsWidthScale(15)));
        make.top.equalTo(dk_HomeAuthLoanHeadLab.mas_bottom).offset(DK_IsWidthScale(11));
        make.height.equalTo(@(DK_IsWidthScale(60)));
    }];
    UIImageView* dk_authHomeLoanAlertImageView = [[UIImageView alloc] init];
    dk_authHomeLoanAlertImageView.userInteractionEnabled = YES;
    dk_authHomeLoanAlertImageView.image = DK_GetImage(@"dk_HomeAuthorizeLimitWarnRed");
    [dk_authHomeLoanAlertBgView addSubview:dk_authHomeLoanAlertImageView];
    [dk_authHomeLoanAlertImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(15)));
        make.top.equalTo(@(DK_IsWidthScale(15)));
        make.width.equalTo(@(DK_IsWidthScale(14)));
        make.height.equalTo(@(DK_IsWidthScale(12)));
    }];
    NSString *loanHead = @"UPI will expire, which may lead to repayment failure. Please use the latest UPI for repayment";
    NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:loanHead];
    [attStr addAttribute:NSFontAttributeName value:DK_FONT_Regular(11) range:NSMakeRange(0,attStr.length)];
    [attStr addAttribute:NSForegroundColorAttributeName value:DK_Hex(@"#333333") range:NSMakeRange(0,attStr.length)];
    [attStr addAttribute:NSForegroundColorAttributeName value:DK_Hex(@"#ED4342") range:NSMakeRange(68,12)];
    UILabel *dk_authHomeLoanAlertLab = [[UILabel alloc] init];
    dk_authHomeLoanAlertLab.attributedText = attStr;
    dk_authHomeLoanAlertLab.numberOfLines = 0;
    [dk_authHomeLoanAlertBgView addSubview:dk_authHomeLoanAlertLab];
    [dk_authHomeLoanAlertLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(dk_authHomeLoanAlertImageView.mas_right).offset(DK_IsWidthScale(10));
        make.right.equalTo(@(-DK_IsWidthScale(30)));
        make.centerY.equalTo(dk_authHomeLoanAlertBgView);
    }];
}
- (void)jumpOrder{
    if(self.MsgAlertGoBlock){
        self.MsgAlertGoBlock();
    }
}
//-(void)setAmount:(NSString *)amount{
//    _amount = amount;
//    if(_amount){
//        self.dk_HomeAuthLoanValueLab.text = [NSString stringWithFormat:@"₹%@",_amount];
//    }else{
//        self.dk_HomeAuthLoanValueLab.text = @"₹0";
//    }
//}
- (void)updateAuthLoan{
    DKUserBaseInfoModel *dk_UserBaseInfoMdl = [DKGlobalHelper defaultManager].userBaseInfoMdl;
    if(self.dk_OrderListMdl.orderRecordList.count > 0){
        self.dk_HomeAuthLoanValueLab.text = [NSString stringWithFormat:@"₹%@",[NSString makeShowMoney:dk_UserBaseInfoMdl.repaymentTotalAmount]];
    }else{
        self.dk_HomeAuthLoanValueLab.text = @"₹0";
    }
}
@end
